var lifeCounter : int = 3;
var extinguisherCharge : double = 50.0;
var maxExtinguisherCharge : double = 50.0;
var chargeRate : double = 50.0;
var dischargeRate : double = 100.0;
var increase : boolean = true;
var extinguisherEmitter : GameObject;
var characterMotor : CharacterMotor;
var extinguisher : Extinguisher;
var isUsingExtinguisher : boolean = false;
var isJumping : boolean = false;
public var hoveringHeight:double = 0.0;

function Start() {
	characterMotor = GetComponent(CharacterMotor);
	extinguisher = GetComponent(Extinguisher);
}

function Update () {
	if(increase && extinguisherCharge < maxExtinguisherCharge){
		extinguisherCharge += chargeRate * Time.deltaTime;
		if(extinguisherCharge > maxExtinguisherCharge) {
			extinguisherCharge = maxExtinguisherCharge;
		}	
	}
	
	if(Input.GetAxis("Horizontal") >= 0.2) {
		this.transform.localScale.x = -1;
	}
	if(Input.GetAxis("Horizontal") <= -0.2) {
		this.transform.localScale.x = 1;
	}
	
	if(Input.GetButtonDown("Jump")){
		if(isJumping) {
			isUsingExtinguisher = true;
			hoveringHeight = this.transform.position.y;
			extinguisher.ExtinguisherOn();
		} else {
			isJumping = true;
			Debug.Log("isJumping");
		}
	}
	if(isUsingExtinguisher){
			if(extinguisherCharge > 1)
			{
				transform.position.y = hoveringHeight - 0.05;
				hoveringHeight = transform.position.y;
			}else 
			{
				isUsingExtinguisher = false;
				 extinguisher.ExtinguisherOff(); 
			}
		RemoveCharge();
	}
	if(Input.GetButtonUp("Jump")){
		isUsingExtinguisher = false;
		extinguisher.ExtinguisherOff();
		IncreaseOn();
	}

	
}

function LateUpdate() {
	isJumping = !characterMotor.IsGrounded();

}

function IncreaseOff(){
	increase = false;
}

function IncreaseOn() {
	increase = true;
}

function RemoveCharge(){
	if(extinguisherCharge > 0){
		extinguisherCharge -= (dischargeRate * Time.deltaTime);
		if(extinguisherCharge < 0){
			extinguisherCharge = 0;
		}
	} else {
		extinguisher.ExtinguisherOff();
		Debug.Log("Off");
	}
}

function RemoveLife() {
	lifeCounter -= 1;
}

function NotJumping() {
	isJumping = false;
}
